$(function() {
	$(".list li").on("mouseover", function() {
		$(this).in();
	});
	$(".list li").on("mouseleave", function() {
		$(".list li").removeIn();
	});

	//优秀人物接口
	people()
	//区县优秀志愿者
	volunteer();

	//公益项目
	project();

	volunteerStar(1, size, modelId);

})

var size = 20;
//志愿之星
var modelId = 5;
//志愿之星-年度人物
var peopleModelId = 16;

function people() {
	$.get(host + "/volunteerStar/getVolunteerStar", {
		"page": 1,
		"size": 5,
		"modelId": peopleModelId
	}, function(data) {
		var showimg = '';
		
		var html = "";
		if(data && data.result.length > 0) {
			$.each(data.result, function(i, n) {
				if(n.imageUrl != null){
					showimg = 'http://101.201.113.151:9000'+n.imageUrl.split('ROOT')[1] ;
				}
				
				html += '<div class="box">';
				html += '<div class="head" style="background-image: url('+showimg+');"></div>';
				html += '<div class="name">'+n.content+'</div>';
				html += '<div class="grade">'+n.description+'</div>';
				html += '<a href="javascript:;"><div class="address">'+n.areaName+'</div></a>';
				//html += '<a href="details_star.html?id='+n.id+'"><div class="address">'+n.areaName+'</div></a>';
				html += '</div>';
			});
		}
		$(".startbox").html(html);

		
		$(".startbox div").on("mouseover", function() {
			$(this).in();
		});
		$(".startbox div").on("mouseleave", function() {
			$(this).removeIn();
		});
	})
}
//区县优秀志愿者
function volunteer() {
	$.get(host + "volunteerStar/getPerfectVolunteer", null, function(data) {

		var html = "";
		if(data && data.length > 0) {
			$.each(data, function(i, n) {
				html += '<li>';
				html += '<div class="name">' + n.areaName + '</div>';
				html += '<div class="progress"></div>';
				html += '<div class="num">' + n.viewNum + '</div>';
				html += '</li>';
			});
		}

		$("#volunteer").html(html);
	})
}
//公益项目
function project() {
	$.get(host + "volunteerStar/getVolunteerProject", null, function(data) {
		var html = "";
		if(data && data.length > 0) {
			$.each(data, function(i, n) {
				var num = "";
				if(i < 9) {
					num = "0" + (i + 1);
				} else {
					num = i;
				}
				html += '<li>';
				html += '<div class="order">' + num + '</div>';
				html += '<div class="name">' + n.areaName + '</div>';
				html += '<div class="num">正在招募:<span>' + n.commonNum + '</span></div>';
				html += '</li>';
			});
		}
		$("#project").html(html);
	})
}

$('#page').bootpag({
	total: 10,
	maxVisible: 10,
	wrapClass: 'pagination',
	activeClass: 'active',
	disabledClass: 'disabled',
	nextClass: 'next',
	prevClass: 'prev',
	lastClass: 'last',
	firstClass: 'first'
}).on('page', function(event, num) {
	volunteerStar(page)

});

function volunteerStar(page) {
	$.get(host + "volunteerStar/getVolunteerStar", {
		"page": page,
		"size": size,
		"modelId": modelId
	}, function(data) {
		fillingData(data.result);
		$('#page').bootpag({
			total: data.allpage,
			maxVisible: 10
		})
	});
}
//填充数据
function fillingData(data) {
	var html = "";
	$.each(data, function(i, n) {
		html += '<a herf="details_star.html?id=' + n.id + '"><li><div class="text">' + n.description + '</div><div class="time">' + n.createDate + '</div></li></a>';
	})
	$("#listdata").html(html);
}